const express = require('express');
const static = require('express-static');
const cookieParser = require('cookie-parser');
const cookieSession = require('cookie-session');
const bodyParser = require('body-parser');
const multer = require('multer');//上传文件模块
const fs = require('fs');
const pathLib = require('path');
const consolidate = require('consolidate');

var server = express(),
    index = require( './routes/index' ),
    zhengwen = require( './routes/zhengwen' ),
    liebiao = require( './routes/liebiao' );

server.listen(8080);

//处理cookie
server.use( cookieParser('FGHJKYUI') );

//使用session
var arr = [];
for( var i = 0; i<100000; i++ )
{
    arr.push( 'session_keys_'+Math.random() );
}

server.use( cookieSession({
    name:'test_session',
    keys:arr,
    maxAge:20*3600*1000
}) );

//post数据
server.use( bodyParser.urlencoded({extended:false}) );

//接受文件上传数据
server.use( multer({dest:"./www/uploade"}).any() );

/*配置模板引擎*/
//1. 输出什么东西
server.set( 'view engine','html' );
//2. 模板文件放在哪儿
server.set( 'views','./templates' );
//3. 哪种模板文件
server.engine( 'html',consolidate.ejs );

server.use( '/', index );

server.use( '/zhengwen',zhengwen );

server.use( '/liebiao',liebiao );

//使用静态数据
server.use(static("./www"));